all: pdf clean

pdf: document.tex
	@echo building document.pdf...
	# OR with true to prevent make from exiting in case of no error found
	-pdflatex -file-line-error -halt-on-error document.tex | grep '.*:[0-9]*:.*' || true
	bibtex document.aux > /dev/null 2>&1
	makeindex document > /dev/null 2>&1
	pdflatex document.tex > /dev/null 2>&1
	pdflatex document.tex > /dev/null 2>&1
	
keeptemp: pdf

clean:
	@echo deleting temporary files...
	rm -f  *.aux *.log *.out *.bbl *.blg *~ *.dvi *.toc *.lot *.lol *.lof *.idx *.ind *.ilg *.snm *.nav *.vrb *.run.xml *.bcf *.nlo *.nls

cleanall: clean
	@echo deleting document.pdf...
	rm -f  *.pdf

.PHONY: all clean cleanall keeptemp pdf
.SILENT: all clean cleanall keeptemp pdf